﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.ComponentModel;
using Microsoft.Crm.Workflow;

namespace CrmContrib.Workflow.Activities.Utilities
{
    [CrmWorkflowActivity("Format String", "CrmContrib \\ Utilities")]
    public class FormatStringActivity : Activity
    {
        [CrmInput("Template")]
        public string Template
        {
            get { return (string)GetValue(TemplateProperty); }
            set { SetValue(TemplateProperty, value); }
        }
        
        public static readonly DependencyProperty TemplateProperty = DependencyProperty.Register("Template", typeof(string), typeof(FormatStringActivity));

        [CrmInput("Input")]
        public string Input
        {
            get { return (string)GetValue(InputProperty); }
            set { SetValue(InputProperty, value); }
        }

        public static readonly DependencyProperty InputProperty = DependencyProperty.Register("Input", typeof(string), typeof(FormatStringActivity));

        [CrmOutput("Output")]
        public string Output
        {
            get { return (string)GetValue(OutputProperty); }
            set { SetValue(OutputProperty, value); }
        }

        public static readonly DependencyProperty OutputProperty = DependencyProperty.Register("Output", typeof(string), typeof(FormatStringActivity));

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            this.Output = string.Format(this.Template, this.Input);

            return base.Execute(executionContext);
        }
    }
}
